<template>
    <!--商户详情-->
    <div>
        <div class="content">
            <div class="banner mb0">
                <mt-swipe :auto="4000" style="height: 129px;">
                    <mt-swipe-item v-for="(v,i) in storeMap.HD" :key="i"><img :src="v.pictureAddress"></mt-swipe-item>
                </mt-swipe>
                <div class="cover">
                    <span class="fr">{{filterObj(storeMap)}}张</span>
                    <i class="all_bg pic fr"></i>
                </div>
            </div>
            <div class="store-tit">
                <p class="name">{{storeMap.storeName}}</p>
                <p class="gray">
                    <span>{{storeMap.oneLevel?storeMap.oneLevel[1]:''}}</span>
                    <span>￥{{storeMap.consumption}}/人</span>
                </p>
                <input type="button" @click.stop="goshop" value="优惠买单">
            </div>
            <div class="contact">
                <a :href="'http://api.map.baidu.com/marker?location='+baiduMap.latitud+','+baiduMap.longitud+'&title='+storeMap.storeAddress+'&content='+storeMap.storeAddress+'&output=html'">
                    <i class="all_bg loca"></i>
                    <span>{{storeMap.storeAddress}}</span>
                </a>
                <a :href="'tel:'+storeMap.storePhone">
                    <i class="all_bg phone"></i>
                    <span>{{storeMap.storePhone}}</span>
                </a>
            </div>
            <div class="link-group">
                <!--券字但是静态里是惠字-闪惠信息-->
                <div v-for="v in CouponsPlayMap.KQLBLST">
                    <a href="javascript:void(0)">
                        <i class="all_bg hui"></i>
                        <span class="text">{{v.ActivityTitle}}</span>
                        <span class="f12">{{v.ActivitySubtitle}}</span>
                        <span class="fr">还剩{{v.remainingNumber}}份</span>
                    </a>
                </div>

                <!--卡字-会员卡列表-->
                <div v-for="v in membershipMap.KQLBLST">
                    <a href="javascript:void(0)" @click="openMemberPage(v)">
                        <i class="all_bg ka"></i>
                        <span class="text">{{v.membershipCardName}}</span>

                        <i class="icon-right fr"></i>
                        <span class="fr">{{v.cardFace}}元储值卡</span>
                    </a>
                </div>
            </div>
            <div class="link-group">
                <!--银字-优惠券-->
                <div v-for="v in CouponsMap.KQLBLST">
                    <a href="javascript:void(0)">
                        <i class="all_bg yin"></i>
                        <span class="text">{{v.ActivityTitle}}</span>
                        <em class="orange">{{v.ActivitySubtitle}}</em>
                        <!--<i class="icon-right fr"></i>-->

                        <button @click.stop="disBtn($event,v.serialNumber)">立即领取</button>
                    </a>
                </div>
            </div>
            <div class="itemlist">
                <div class="itemtop">
                    <h3>商户信息</h3>
                </div>
                <div class="iteminfo store">
                    <p class="gray" v-for="(v,i) in storeMap.zzfwlist" :key="i">
                        <i :class="'icon_bg '+ v.zzfwtittle"></i>
                        <span>{{v.zzfwName}}</span>
                    </p>
                    <!-- <p class="gray">
                        <i class="icon_bg bx"></i>
                        <span>包厢</span>
                    </p>
                    <p class="gray">
                        <i class="icon_bg ltw"></i>
                        <span>露天位</span>
                    </p>
                    <p class="gray">
                        <i class="icon_bg tc"></i>
                        <span>停车</span>
                    </p>
                    <p class="gray">
                        <i class="icon_bg bby"></i>
                        <span>宝宝椅</span>
                    </p>
                    <p class="gray">
                        <i class="icon_bg wyq"></i>
                        <span>无烟区</span>
                    </p>
                    <p class="gray">
                        <i class="icon_bg sk"></i>
                        <span>刷卡</span>
                    </p>
                    <p class="gray">
                        <i class="icon_bg allday"></i>
                        <span>24小时</span>
                    </p>
                    <p class="gray">
                        <i class="icon_bg ykp"></i>
                        <span>云开票</span>
                    </p>
                    <p class="gray">
                        <i class="icon_bg wm"></i>
                        <span>外卖</span>
                    </p>
                    <p class="gray">
                        <i class="icon_bg qt"></i>
                        <span>其他</span>
                    </p> -->
                    <p class="gray clear">营业时间：{{storeMap.worktime}}</p>
                </div>
            </div>
        </div>
        <a class="my-link-icon" @click="gocenter"></a>

        <form method="post" id="toshopdetail" :action="etsUrl+'h5pay/index.do?newVersion=1.0'">
            <input type="hidden" :value="val" :name="key" v-for="(val,key) in toshopdetail"/>
        </form>
        <form method="post" id="toMycenter" :action="etsUrl+'h5pay/myCenter.do?newVersion=1.0'">
            <input type="hidden" :value="val" :name="key" v-for="(val,key) in toMycenter"/>
        </form>
    </div>
</template>

<script>
    import {mapGetters} from 'vuex';
    import util from '@/util/util';
    import {Indicator} from 'mint-ui';
    export default {
        name: "goodsDetail",
        data(){
            return {
                getYanQianParam:'',//验签参数
                toMycenter:{},
                toshopdetail:{},
                goodsOne:{}//主页传过来的
            }
        },
        methods:{
            openMemberPage(v){
                sessionStorage.setItem('memberObj',JSON.stringify(v));
                this.$router.push({path:'/cardDetail'});
            },
            //解决初始化取不到length报error，因为双向绑定，数据来了后面流程又正常，只是看着不舒服
            filterObj(obj){
                return util.isValidate(obj)&&util.isValidate(obj.HD)?obj.HD.length:0;
            },
            async gocenter(){
                let params = {
                    pickupUrl:this.etsUrl+'service/index.html?'+this.getYanQianParam,//返回地址
                    version:'1.0',
                    merchantId:this.goodsOne.merchantId//商户编号
                }
                await util.axiosPost('/service/consume/ToMycenterServlet.do',params).then(resp=>{

               	   this.toMycenter = resp.data;

               });
                //用表单提交不用href是因为有转码的问题，href是url拼字符串
               document.getElementById('toMycenter').submit();
            },
            titleStr(str){
                return str?str.substring(0,5):str;
            },
            disState(v){
                v.activeState = '0';
            },

            //领取优惠券
            disBtn(v,dateid){
                let params = {
                    serialNumber:dateid,//优惠规则编号	Y
                    merchantId:this.goodsOne.merchantId//商户编号
                };
                let cur = v.currentTarget;
                util.axiosPost('/service/consume/GetCouponServlet.do',params).then(resp=>{
                    //1-新领取，0-以前已经领取过，2-未领取 表示领取失败
                    if(resp.data.stata==='1'){
                        cur.innerText = '已领取';
                    }else if(resp.data.stata==='0'){
                        cur.innerText = '您已领取过';
                    }else if(resp.data.stata==='2'){
                        cur.innerText = '领取失败';
                    }
                });
                cur.className='disabled';
            },

            //优惠买单
            async goshop (){
            	let paramst = {
                    version:'1.0',//固定值1.0                                      n
                    //merchantBranchCode:'549900760001',//商户分店编号                 **************y         storeId
                    merchantBranchCode:this.goodsOne.storeId,//商户分店编号       **************y         storeId
                    receiveUrl:this.etsUrl+'service/index.html?'+this.getYanQianParam+'#/goodsDetail',//服务器接受支付结果的后台通知        **************y   娜姐   自己的路由随意一个地址不报404就行
                    inputCharset:'1',//字符集格式 1 UTF-8 n
                    orderAmount:'0',//默认送0 n
                    //merchantId:'008210249000001',//商户号                           **************y  merchantId
                    merchantId:this.goodsOne.merchantId,//商户号                  **************y  merchantId
                    subBusinessType:'0409',//业务子类型 n
                    payRule:'01',//00:支付 01:试算 n
                    pickupUrl:this.etsUrl+'service/index.html?'+this.getYanQianParam+'#/goodsDetail',//返回地址                             **************y 优惠买单成功以后的url，问业务
                    orderCurrency:'0',//订单金额币种类型      0代表人民币 n
                    ext1:'TL_QIANBAO',//扩展字段1 n
                    businessCode:'0135',//业务授权码 n
                    orderExpireDatetime:'2880',//订单有效期 n
                    payType:'0',//支付方式0 n
                    //productName:'买宝马',//订单名称                                  **************y
                    appId:'TLA0001'//接入机构送TLA0001  n
                };
                await util.axiosPost('/service/consume/MembershipCardOrder.do',paramst).then(resp=>{

                      this.toshopdetail = resp.data.toshopdetail;
                      //用表单提交不用href是因为有转码的问题，href是url拼字符串
                      //if(resp.data)  document.getElementById('toshopdetail').submit();
               	   //console.log(this.toshopdetail);
                   //let detail = qs.stringify(resp.data.toshopdetail);
                   //location.href = 'http://test.allinpay.com/h5pay/index.do?newVersion=1.0&'+detail;
               });
                document.getElementById('toshopdetail').submit();

            }
        },
        created(){
            Indicator.open();//遮罩层

            let search = location.search.substring(1,location.search.length);
            let res = util.convertUrlToJSON(search);
            console.log(res);

            //判断是否是扫码进来的
            if(util.isValidate(res.merchantId)){
                //扫码过来的 window.location.href="http://192.168.12.165:8080/ums?storeId=${FDBH}&merchantId=${SHBH}&longitude=210&latitude=130#/goodsDetail";
                //http://test.allinpay.com/service/index.html?storeId=076301230000&merchantId=008310107630123&longitude=210&latitude=130#/goodsDetail

                this.longitude = res.longitude;//经度
                this.latitude = res.latitude;//纬度
                this.goodsOne.storeId = res.storeId;
                this.goodsOne.merchantId = res.merchantId;
                sessionStorage.setItem('goodsOne',JSON.stringify(res));

                //this.etsUrl = addressObj.etsUrl;
            }else{
                this.goodsOne = JSON.parse(sessionStorage.getItem('goodsOne'));//主页传过来的数据
            }
            console.log(this.goodsOne);
            let param = {
                appId:'0002',
                sysId:this.goodsOne.merchantId
            };
            this.$store.dispatch('membershipServelt',param).then(resp=>{
                console.log(resp.data);
                this.getYanQianParam = resp.data.backUrlparamter;
            });
            this.$store.commit('setImgBaseUrl',process.env.NODE_ENV);//process.env.NODE_ENV获取配置文件是dev还是build  值分别为development和production
        },
        mounted() {

            let params= {
                //storeId:'549900760000',
                //merchantId:'008310153110000',
                storeId:this.goodsOne.storeId,
                merchantId:this.goodsOne.merchantId,
                longitude:this.longitude,//经度
                latitude:this.latitude,//纬度
            };
            this.$store.dispatch('loadGoodsDetail',params).then(()=>{
                Indicator.close();//数据请求完，关闭遮罩层
            });
        },
        computed:{
            storeMap(){
                return this.$store.getters.getStoreMap?this.$store.getters.getStoreMap:{};//给个初始化数据{}
            },

            ...mapGetters({
                //getYanQianParam:'getYanQianParam',//验签参数
                etsUrl:'getEtsUrl',
                CouponsMap:'getCouponsMap',
                membershipMap:'getMembershipMap',
                baiduMap:'getBaiduMap',
                //storeMap:'getStoreMap',
                CouponsPlayMap:'getCouponsPlayMap',
                longitude:'getLongitude',//经度
                latitude:'getLatitude'//纬度
            })
        }
    }
</script>

<style scoped>

</style>
